package infrastructure;

import infrastructure.configuration.Configuration;
import infrastructure.exceptions.ServerFataError;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.logging.LogManager;

/**
 * This initializer initializes the system for operation
 * @author sashas
 *
 */
public class Initializer {
	
	/**
	 * Initializes the system. If system cannot be initialized the {@link ServerFataError} exception is thrown 
	 */
	public static synchronized void initialize() {
		
		FileInputStream loggerIn = null;
		try{
			
			// build log configuration file stream
			loggerIn = new FileInputStream(Configuration.getInstance().getLogConfigurationFileName());
			LogManager.getLogManager().readConfiguration(loggerIn);
		}catch(Exception ex){
			throw new ServerFataError("Initialization failed .. server will be closed", ex);
		}finally{
			if (null != loggerIn){
				try{
					loggerIn.close();
				}catch(IOException ex){
					// Do nothing ..
				}
				
			}
		}
	}
}
